﻿using Autofac;
using System.Reflection;

namespace TemplateApiCore.Config
{
    public class AutofacModuleRegister : Autofac.Module
    {
        /// <summary>
        /// 重写Autofac管道Load方法，在这里注册注入
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            #region 注入接口服务
            Assembly interfaceAssembly = Assembly.Load("TemplateInterfaceService");
            Assembly serviceAssembly = Assembly.Load("TemplateService");
            builder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly).AsImplementedInterfaces().InstancePerLifetimeScope();//PropertiesAutowired().InstancePerLifetimeScope();
            #endregion

            #region 注入接口Dao
            Assembly daoInterfaceAssembly = Assembly.Load("TemplateDao");
            Assembly daoAssembly = Assembly.Load("TemplateInterfaceDao");
            builder.RegisterAssemblyTypes(daoInterfaceAssembly, daoAssembly).AsImplementedInterfaces().InstancePerLifetimeScope();//.PropertiesAutowired().InstancePerLifetimeScope();
            #endregion
        }
    }
}
